package com.nintendo.controller;

import com.nintendo.config.MinioConfig;
import com.nintendo.utils.IMoocJSONResult;
import com.nintendo.utils.MinioUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
public class FileController {
    @Autowired
    private MinioUtils minioUtils;
    @Autowired
    private MinioConfig minioConfig;
    @PostMapping("/upload")
    public IMoocJSONResult upload(@RequestParam("file") MultipartFile file) throws Exception {
        String url = minioUtils.upload(file);
        url = "http://"+minioConfig.getEndpoint()+":"+minioConfig.getPort()+"/"+url;
        System.out.println(url);
        return IMoocJSONResult.ok(url);
    }
}
